#include <iostream>
#include <queue>

#include "common/utils.hpp"

TreeNode* minNode;

bool traversal(TreeNode* root) {
    if (root == nullptr) return true;

    bool l = traversal(root->left);
    
    bool curr = true;
    if (minNode != nullptr && minNode->val >= root->val) curr = false;
    else minNode = root;

    bool r = traversal(root->right);

    return l && r && curr;
}

/*
不能单纯的比较左节点小于中间节点，右节点大于中间节点就完事了，
整个左子树都要小于右子树才行
*/

bool isValidBST(TreeNode* root) {
    return traversal(root);
}

extern TreeNode* commonRoot;

int main() {
    std::vector<int> nums = { 2, 1, 3 };
    TreeNode* node = createTreeNodeByArray(nums);
    printTreeNode(node);
    std::cout << "=================\n";
    bool ret = isValidBST(node);
    std::cout << "ret: " << ret;
}